package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
public class WmchannelController {
@Autowired
    WmChannelService wmChannelService;
//显示所有频道
    @GetMapping("/channels")
    public ResponseResult findAll(){
        List<WmChannel> list = wmChannelService.list();
        return ResponseResult.okResult(list);
    }
    //频道名称模糊分页查询
    @PostMapping("/list")
    public ResponseResult list(@RequestBody SensitiveDto dto){
        return   wmChannelService.listPage(dto);
    }
    //删除频道
    @GetMapping("/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        return wmChannelService.deleteById(id);
    }
    //保存频道
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel dto){
        return wmChannelService.saveWmChannel(dto);
    }
    //修改频道
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel dto){
        return wmChannelService.updateWmChannel(dto);
    }

}